from ProjectTool.WebTool.config.conf import DRIVER_PATH

from selenium import webdriver
import time
import jsonpath
import json


# token_js_str = "window.localStorage.setItem('{key}','{value}')".format(key='userInfo',
#                                                                             value='{"id":1,"username":"jiang","head_img":null,"name":null,"sex":null,"age":null,"status":2,"access_token":"a1da8426-e543-442c-9cdb-8638d4caeb1d"}')
#
# driver = webdriver.Chrome(executable_path=DRIVER_PATH)
# url = 'http://127.0.0.1:8113/OftenMyTool'
# driver.get(url)
# driver.execute_script(token_js_str)
# time.sleep(5)
# driver.get('http://www.baidu.com')
# driver.quit()
# time.sleep(3)

def get_value(json_data, out_str):
    value = jsonpath.jsonpath(json_data, out_str)
    if value is not False:
        value = value[0]
    return value

json_data = '{"userInfo":{"id":1,"username":"jiang","head_img":null,"name":null,"sex":null,"age":null,"status":2,"access_token":"a1da8426-e543-442c-9cdb-8638d4caeb1d"}}'
token_js_str = "window.localStorage.setItem('{key}','{value}')"
a = {'1': 2, '2': 3}

b = '测试字典插入{a}'.format(a=a)
print(b)

print(get_value(json.loads(json_data),'$.userInfo'))
json_data = json.loads(json_data)
for json_key in json_data:
    key = '$.{key}'.format(key=json_key)
    value = get_value(json_data,key)
    token_js_str = token_js_str.format(key=json_key,value=json.dumps(value))
    print(token_js_str)


a = [1,2,3]
b = [4,5,6]
a += b
print(a)
